﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using AssetAllocationSystem.Models;
using NHibernate;
using NHibernate.Criterion;

namespace AssetAllocationSystem.Repositories
{
    public class AssetVendorRepository : RepositoryBase<AssetVendor>
    {
        private ISession session;
        public AssetVendorRepository(ISession session) : base(session)
        {
            this.session = session;
        }

        public IList<AssetVendor> FindByAssetId(Guid assetId)
        {
            var assetVendors = DetachedCriteria
                .For<AssetVendor>()
                .CreateAlias("Asset", "asset")
                .Add(Restrictions.Eq("asset.Id", assetId))
                .GetExecutableCriteria(session)
                .List<AssetVendor>();

            return assetVendors;
        }

        public IList<AssetVendor> FindByVendorId(Guid vendorId)
        {
            var allocations =
                DetachedCriteria
                .For<AssetVendor>()
                .CreateAlias("Vendor", "vendor")
                .Add(Restrictions.Le("vendor.Id", vendorId))
                .GetExecutableCriteria(session)
                .List<AssetVendor>();

            return allocations;
        }
    }
}